module.exports = function ($scope, $state, $resource, $modal, toaster) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
	};
		/* 分页
   * ========================================= */
  $scope.maxSize = 5;            //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10; 
  $scope.searchform = {};
	//卡列表
	

  // $scope.loadlist();
  // 城市列表
  $scope.getArea = function(){
      $resource('/api/as/puc/authorizedt/findAddressCodeList', {}, {}).save({}, function(res){
          if(res.errcode === 0){
              $scope.provincelist = res.data;
              console.log($scope.provincelist);
              $scope.loadlist = function () {
                var para = {
                    pageNo:$scope.bigCurrentPage, 
                    pageSize:$scope.itemsPerPage
                };
                para = angular.extend($scope.searchform, para);
                $resource('/api/as/mc/apply/findShopList', {}, {}).save(para, function (res) {
                  if (res.errcode === 0) {
                    $scope.objs = res.data.results;
                    $scope.bigTotalItems = res.data.totalRecord;
                    for (var i = 0; i < $scope.objs.length; i++){
                      if ($scope.objs[i].city_id) {
                        var cityIdArr = $scope.objs[i].city_id.split(',');
                        console.log(cityIdArr);
                        console.log(cityIdArr.length);
                        var nameArr = [];
                        for (var k = 0; k < cityIdArr.length; k++) {
                          console.log('cityid' + k);
                          console.log('!!!!');
                          console.log('22222' + $scope.provincelist);
                          console.log('111111' + $scope.provincelist.length);
                            for (var j = 0; j < $scope.provincelist.length; j++){
                              console.log($scope.provincelist[j]);
                              console.log(cityIdArr[k]);
                              if (cityIdArr[k] == $scope.provincelist[j].id) {
                                console.log('~~~~~');
                                nameArr.push($scope.provincelist[j].address);
                                console.log(nameArr);
                                $scope.objs[i].city = nameArr.join(',');
                              }
                            }
                        }
                      }
                    }
                    
                  } else {
                    toaster.error({ title: '', body: res.errmsg });
                  }
                });
                
              }
              $scope.loadlist();

          }else{
              toaster.error({title: '', body: res.errmsg});
          }
      });
  }
  $scope.getArea();

};